#include "dopplerspectrumdisplaywidget.h"
#include <QGridLayout>
#include <QLabel>
DopplerSpectrumDisplayWidget::DopplerSpectrumDisplayWidget(QWidget *parent)
    : QWidget(parent)
{
    this->setWindowTitle("DopplerDisplay");
//    this->setStyleSheet("background-color:black;");
    this->resize(800,500);

    m_customPlot = new QCustomPlot(this);
    m_layout = new QGridLayout(this);
    m_layout->setContentsMargins(0,0,0,0);
    this->configplot(m_customPlot);
    m_layout->addWidget(m_customPlot,0,0);


}

DopplerSpectrumDisplayWidget::~DopplerSpectrumDisplayWidget()
{

}


/** 配置曲线图界面参数
 *@author Yguohang
 *@return QCustomplot
 */
void DopplerSpectrumDisplayWidget::configplot(QCustomPlot * customPlot)
{

//    customPlot->resize(800,500);
    customPlot->addGraph(0);  //添加数据曲线
    customPlot->graph(0)->setPen(QPen(Qt::blue));  //设置画笔 蓝线
//    customPlot->axisRect()->setupFullAxesBox(false);    //上边沿于下边沿不显示

//    QSizePolicy spRight(QSizePolicy::Preferred, QSizePolicy::Preferred);  //缺省大小为最佳效果 部件允许放大和缩小
//    spRight.setHorizontalStretch(1); //设置水平缩放比例因子
//    spRight.setVerticalStretch(1); //设置垂直缩放比例因子
//    customPlot->setSizePolicy(spRight);
    //自动设置显示界面的范围
    customPlot->graph(0)->rescaleAxes();
    //设置绘制输出图像界面缩放
    customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
    //设置绘图x轴范围 先固定大小 可设置解析长度
    customPlot->xAxis->setRange(0, 300);
    //设置绘图y轴范围 y轴范围可不用解析
    customPlot->yAxis->setRange(0, 255);

    //x轴参数配置
    customPlot->xAxis->setBasePen(QPen(Qt::black));  //基础线
    customPlot->xAxis->setTickPen(QPen(Qt::black));  //刻度
    customPlot->xAxis->grid()->setVisible(true);  //网格线可见
    customPlot->xAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine)); //网格线颜色及线样式
    customPlot->xAxis->setTickLabelColor(Qt::black);    //x轴刻度线文字颜色、
    customPlot->xAxis->setLabelColor(Qt::black);    //x轴标签颜色
    customPlot->xAxis->setLabel("距离门");    //x轴标签值

    //y轴参数配置
    customPlot->yAxis->setBasePen(QPen(Qt::black));
    customPlot->yAxis->setTickPen(QPen(Qt::black));
    customPlot->yAxis->grid()->setVisible(true);
    customPlot->yAxis->grid()->setPen(QPen(QColor(130, 130, 130), 0, Qt::DotLine));
    customPlot->yAxis->setTickLabelColor(Qt::black);
    customPlot->yAxis->setLabelColor(Qt::black);
    customPlot->yAxis->setLabel("信号幅值");

    return ;
}


/**
 * @brief 数据绘图槽函数
 */
void DopplerSpectrumDisplayWidget::rec_data_plot(uint8_t *data, uint32_t data_size)
{
    QVector<double> Data(data_size);
    QVector<double> Data_size(data_size);
    for(uint32_t i = 0; i<data_size ;i++)
    {
        Data_size[i] = i / 10;
        Data[i] = *data;
        data++;
    }
    this->m_customPlot->graph()->setData(Data_size,Data);
    this->m_customPlot->rescaleAxes(true);
    this->m_customPlot->replot();
}


void DopplerSpectrumDisplayWidget::test_data_plot()
{
    QVector<QCPGraphData> timeData(250);
     for (int i=0; i<250; ++i)
     {
       timeData[i].key =i;
       timeData[i].value = i * i;

     }
     m_customPlot->graph()->data()->set(timeData);
}
